<?php

	require_once('config.php');
	// import the needed configs

	class dal
	{

		var $link = NULL;
	
		function connect_to_db()
		{
			$this->$link = mysql_connect(DB_HOST, DB_USER_NAME, DB_PASSWORD);
			if (!$this->$link) {
				die('Could not connect: ' . mysql_error());
			}
			
			// no select the db
			
			$db_selected = mysql_select_db(DB_NAME, $this->$link);
			if (!$db_selected) {
				$this->connect_to_db();
				die ('Can\'t use this db: ' . mysql_error());
			}
		}
		
		function disconnect_from_db()
		{
			mysql_close($this->$link);
		}
		
		function execute_query($query)
		{
			$result = mysql_query($query);
			if (!$result) {
				$this->disconnect_from_db();
				die('Invalid query: ' . mysql_error());
			}
			
			return $result;
		}
	
	}

?>